﻿namespace EasyWeb.Data.EntityFramework.Models.Mapping
{
    using System;
    using System.Collections.Generic;
    using System.Data.Entity.ModelConfiguration;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    internal class EWSelectionItemDefinitionModelMapping : EntityTypeConfiguration<EWSelectionItemDefinitionModel>
    {
        public EWSelectionItemDefinitionModelMapping()
        {
            // key mappings

            this.ToTable("ew_tbl_selection_items");

            this.HasKey(m => m.Id);

            this.Property(m => m.Id)
                .HasColumnName("ew_uid_selection_item_id")
                .IsRequired();

            this.Property(m => m.Created)
                .HasColumnName("ew_dt_created")
                .IsRequired();

            this.Property(m => m.CreatedBy)
                .HasColumnName("ew_nvc_created_by")
                .IsRequired()
                .HasMaxLength(1024)
                .IsUnicode()
                .IsVariableLength();

            this.Property(m => m.Modified)
                .HasColumnName("ew_dt_modified")
                .IsRequired();

            this.Property(m => m.ModifiedBy)
                .HasColumnName("ew_nvc_modified_by")
                .IsRequired()
                .HasMaxLength(1024)
                .IsUnicode()
                .IsVariableLength();

            this.Property(m => m.Timestamp)
                .HasColumnName("ew_t_timestamp")
                .IsRowVersion();

            // other mappings

            this.Property(m => m.Key)
                .HasColumnName("ew_vc_key")
                .IsRequired()
                .HasMaxLength(512)
                .IsUnicode(false)
                .IsVariableLength();

            this.Property(m => m.Value)
                .HasColumnName("ew_xml_value")
                .IsRequired()
                .HasColumnType("XML");

            this.Property(m => m.SelectionDefinitionId)
                .HasColumnName("ew_uid_selection_id")
                .IsRequired();

            this.HasRequired(m => m.SelectionDefinition)
                .WithMany(m => m.SelectionItemDefinitions)
                .HasForeignKey(m => m.SelectionDefinitionId);
        }
    }
}
